<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>相册衣服切换</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        ul {
            list-style: none;
        }
        ul li {
            float: left;
            margin-left: 15px;
            width: 50px;
            height: 50px;
        }
        .active {
            border: 1px solid red;
        }
    </style>
</head>
<body>
    <img id="bigImg"  src="img/1.jpg" alt="" width="400px" height="400px">
    <ul>
        <li class="active"><a href=""><img class="smallImg" src="img/1.jpg" alt="" width="50px" height="50px"></a></li>
        <li><a href=""><img class="smallImg" src="img/2.jpg" alt="" width="50px" height="50px"></a></li>
        <li><a href=""><img class="smallImg" src="img/3.jpg" alt="" width="50px" height="50px"></a></li>
        <li><a href=""><img class="smallImg" src="img/4.jpg" alt="" width="50px" height="50px"></a></li>
        <li><a href=""><img class="smallImg" src="img/5.jpg" alt="" width="50px" height="50px"></a></li>
    </ul>
    <script>
        var bigImg=document.getElementById('bigImg');
        var smallImgs=document.getElementsByClassName('smallImg');
        //遍历集合，给每个img标签添加事件
        for(var i=0;i<smallImgs.length;i++){
            smallImgs[i].onmouseover=function(){   
                for(var j=0;j<smallImgs.length;j++){
                    //设置li标签的类名为空
                    smallImgs[j].parentNode.parentNode.setAttribute('class','');
                }
                //修改大图片的属性值
                var smallImgSrc=this.getAttribute('src');
                bigImg.setAttribute('src',smallImgSrc);
                //给鼠标经过时的img添加类
                this.parentNode.parentNode.setAttribute('class','active');
            }

        }
    </script>
</body>
</html>